package org.example.javax.script;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * @author juntao zhang
 * @since 2015/10/27 15:41
 */
public class JSTest
{
    public static void main(String[] args)
    {
        long start = System.currentTimeMillis();
        int i=100000;
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine engine = mgr.getEngineByExtension("js"); //this cost too much
        while (i-->0)
        {
            try
            {
                engine.put("name","Tunnel0");
                engine.put("state","down");
                boolean res= (boolean) engine.eval("(name.toLowerCase()=='tunnel0')&&(state.toLowerCase()=='down')");
                System.out.println(res);
            }
            catch (ScriptException e)
            {
                e.printStackTrace();
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("cost "+(end-start));
    }
}
